package org.example.hengshengexam;

import java.io.*;
import java.util.*;

public class CalculatorQi {
    public static void main(String[] args) throws IOException {
        // ACM 模式的输入输出
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer st = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        while (true) {
            String line = br.readLine();
            if (line == null || line.trim().isEmpty()) break; // EOF 或空行结束
            try {
                double result = evaluate(line);
                out.println(result);
            } catch (Exception e) {
                out.println("ERROR");
            }
        }

        out.flush();
    }

    // 计算表达式的值（支持 + - * / 和括号）
    private static double evaluate(String expr) {
        // 去掉空格
        expr = expr.replaceAll("\\s+", "");
        return parseExpression(new StringTokenizer(expr, "+-*/()", true));
    }

    private static double parseExpression(StringTokenizer tokens) {
        Stack<Double> values = new Stack<>();
        Stack<Character> ops = new Stack<>();

        while (tokens.hasMoreTokens()) {
            String token = tokens.nextToken();

            if (token.equals("(")) {
                // 括号内递归计算
                String inner = getInnerExpr(tokens);
                values.push(evaluate(inner));
            } else if (isNumber(token)) {
                values.push(Double.parseDouble(token));
            } else if (isOperator(token.charAt(0))) {
                char op = token.charAt(0);
                while (!ops.isEmpty() && precedence(ops.peek()) >= precedence(op)) {
                    values.push(applyOp(ops.pop(), values.pop(), values.pop()));
                }
                ops.push(op);
            }
        }

        while (!ops.isEmpty()) {
            values.push(applyOp(ops.pop(), values.pop(), values.pop()));
        }

        return values.pop();
    }

    private static boolean isNumber(String s) {
        return s.matches("-?\\d+(\\.\\d+)?");
    }

    private static boolean isOperator(char c) {
        return c == '+' || c == '-' || c == '*' || c == '/';
    }

    private static int precedence(char op) {
        if (op == '+' || op == '-') return 1;
        if (op == '*' || op == '/') return 2;
        return 0;
    }

    private static double applyOp(char op, double b, double a) {
        switch (op) {
            case '+': return a + b;
            case '-': return a - b;
            case '*': return a * b;
            case '/': return b == 0 ? Double.NaN : a / b;
            default: return 0;
        }
    }

    // 获取括号内完整表达式
    private static String getInnerExpr(StringTokenizer tokens) {
        StringBuilder sb = new StringBuilder();
        int cnt = 1;
        while (tokens.hasMoreTokens()) {
            String t = tokens.nextToken();
            if (t.equals("(")) cnt++;
            else if (t.equals(")")) cnt--;
            if (cnt == 0) break;
            sb.append(t);
        }
        return sb.toString();
    }
}